package com.liu.fresh.biz.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liu.fresh.biz.IAdminInfoBiz;
import com.liu.fresh.entity.AdminInfo;
import com.liu.fresh.mapper.IAdminInfoMapper;
import com.liu.fresh.util.StringUtil;




@Service
public class AdminInfoBizImpl implements IAdminInfoBiz {
	@Autowired
	private IAdminInfoMapper mapper;

	@Override
	public AdminInfo login(String aname, String pwd) {
		if(StringUtil.checkNull(aname ,pwd)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aname", aname);
		map.put("pwd", pwd);
		return mapper.login(map);
	}

	@Override
	public int checkInfo(Map<String, String> map) {
		if(StringUtil.checkNull(map.get("email"), map.get("aname"))){
			return -1;
		}
		return mapper.checkInfo(map);
	}


	@Override
	public int reg(AdminInfo af){
		if(StringUtil.checkNull(af.getAname(), af.getPwd(), af.getTel())){
			return -1;
		}

		return  mapper.reg(af);
	}

	@Override
	public List<AdminInfo> findAll() {
		return mapper.findAll();
	}

	@Override
	public int add(String aname, String pwd, String tel) {
		if(StringUtil.checkNull(aname, pwd, tel)){
			return -1;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aname", aname);
		map.put("pwd", pwd);
		map.put("tel", tel);
		return mapper.add(map);
	}

	@Override
	public int update(String aid, String tel) {
		if(StringUtil.checkNull(aid,tel)){
			return -1;
		}
		String phone=tel.substring(5);
		System.out.println(phone);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aid", aid);
		map.put("tel", phone);
		return mapper.update(map);
	}

	@Override
	public int del(String aid) {
		if(StringUtil.checkNull(aid)){
			return 0;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aid", aid);
		return mapper.del(map);
	}
	

}
